package edu.cmu.cs214.hw9.facelook;

// Manages the special registration functions of the server.  

public class Registration {
	
	private String username = "";
	private String password = "";
	private String email = "";
	private String confirmEmail = "";
	
	// These values should come from the GUI.
	public Registration(String desiredUsername, String desiredPassword, 
			String desiredEmail, String confirmEmail) {
		// If running concurrent code, this could get interrupted in the middle and then
		// username, password, email, or confirm email could be blank.
		this.username = desiredUsername;
		this.password = desiredPassword;
		this.email = desiredEmail;
		this.confirmEmail = confirmEmail;
	}
	
	
	// This should check the "server" to see whether the username exists and password is valid
	public boolean isUserValid() {
		boolean validInformation = false;
		if (usernameExists() || passwordInvalid() || emailInvalid() || emailsDontMatch())
			return false;
		else
			return true;
	}
	
	// The email and confirm email on registration form have to match.
	private boolean emailsDontMatch() {
		if (email.compareToIgnoreCase(confirmEmail) == 0)
			return true;
		else
			return false;
	}


	// Email is invalid if it already exists in database or it doesnt include @ sign.
	// Make sure to write Emails Dont Match.
	private boolean emailInvalid() {
		if (email.contains("@") /* && call to database doesnt return duplicate */)
			return true;
		// Write me to include call to database to see if it already exists. 
		// This should probably be a helper method in the Database.java
		else
			return false;
	}


	/* The string username is grabbed from the GUI.   If it exists in the database
	 * already it is a taken username and should not be added to the database or 
	 * we should not allow it to be registered.
	 */
	public boolean usernameExists() {
		if (username.length() == 0)
			return false; // Should also return false if empty.
		else
			return true; // Write me.
	}
	
	// The password section should not be empty when registering.
	public boolean passwordInvalid() {
		if (password.length() == 0)
			return false; 
		else
			return true;
	}
	

	
}
	

